package com.onekbase.demo.mybatis.config;

import com.onekbase.demo.mybatis.intercept.ExamplePlugin;
import com.onekbase.demo.mybatis.intercept.ExamplePlugin2;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.util.Properties;

@Configuration
@MapperScan("com.onekbase.demo.mybatis.mapper")
public class MybatisConfig {
    @Bean
    public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource){
        SqlSessionFactoryBean sqfb =new SqlSessionFactoryBean();
        sqfb.setDataSource(dataSource);
        sqfb.setPlugins(new ExamplePlugin(),new ExamplePlugin2());
        Properties prop=new Properties();
        prop.put("logImpl","org.apache.ibatis.logging.stdout.StdOutImpl");
        sqfb.setConfigurationProperties(prop);
        return sqfb;
    }
}
